// pages/float/float.js
Page({
  data: {
    addTimes:[],
    sqsy:[],
    gzlist:[Number,Number,Number,Number,Number,Number,Number,Number,Number,Number,Number,Number],
    sr:['sqsy1','sqsy2','sqsy3','sqsy4','sqsy5','sqsy6','sqsy7','sqsy8','sqsy9','sqsy10','sqsy11','sqsy12']
  },
  addAInsurance:function(e){
    console.log("添加成功");
    var k= this.data.addTimes.length;
    var addTimes = "addTimes["+k+"]"
    this.setData({
      [addTimes]:e.detail
    });
  },
  getZxfj:function(e){
    console.log(e.detail);
  },
  //当输入某一个月份的时候，其他月份也会改变
  onInput:function(e){
    var id = e.currentTarget.id;
    for(var l = id;l<12;l++){
      var gztemp = "gzlist["+l+"]";
      this.setData({
        [gztemp] : e.detail.value
      });
    }
    var t = e.detail.value;
    for(var g = 0;g<t.length;g++){
      if((t[g]>'9'||t[g]<'0')&&t[g]!='.'){
        wx.showToast({
              title: '请输入正实数哦',
              icon:'none',
              duration: 1000
            });
      }
  }
  //正则不太好使，还有待解决
  // if(!(/^[0-9]+.?[0-9]*$/.test(e.detail.value))){
  //   wx.showToast({
  //     title: '请输入正实数哦',
  //     icon:'none',
  //     duration: 2000
  //   });
  },
  //提交表单的操作，主要对数据进行一个初步处理
  formSubmit:function(e){
    let additionalComponent = this.selectComponent('#additional');
    let insuranceComponent = this.selectComponent('#insurance');
    let dataFromComponent = additionalComponent.pushData();
    let dataFromComponent1 = insuranceComponent.pushData();
    Object.keys(dataFromComponent).forEach(key => {
      e.detail.value[key] = dataFromComponent[key]
    });
    console.log(e.detail.value);
    Object.keys(e.detail.value).forEach(key => {//转化为浮点数
      e.detail.value[key] = parseFloat(e.detail.value[key]);
    });
    // var tempArr=[];
    // for(var i = 0;i<this.data.sr.length;i++){
    //   tempArr.push(e.detail.value[this.data.sr[i]]);//把税前收入添加到临时数组
    // }
    e.detail.value.sqsy = dataFromComponent1.sqsy;//添加税前收入数组
    e.detail.value.wxyj = dataFromComponent1.wxyj;
    e.detail.value.QueryType = 20;
    wx.navigateTo({
      url: '../result/result?data=' + JSON.stringify(e.detail.value)//json传输
    })
  }
})